import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/utils/extension.dart';
import 'package:pornhub_app/views/mine/profit/dynamic/profit_dynamic.dart';
import 'package:pornhub_app/views/mine/profit/profit_spread.dart';
import 'package:pornhub_app/views/mine/profit/video/profit_video.dart';

import '../../../assets/styles.dart';
import '../../../components/tab_bar_indicator/easy_fixed_indicator.dart';
import 'brushvideo/profit_brushvideo.dart';

class ProfitMain extends StatelessWidget {
  const ProfitMain({super.key});

  static final titles = ["推广收益", "帖子收益", "刷片收益", "视频收益"];

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: titles.length,
      child: Scaffold(
        backgroundColor: Colors.white,
        appBar: _buildAppBarView(),
        body: TabBarView(
            children: titles.map((e) {
          if (e == '帖子收益') {
            return const ProfitDynamic();
          }
          if (e == '刷片收益') {
            return const ProfitBrushVideo();
          }
          if (e == '视频收益') {
            return const ProfitVideo();
          }
          return const ProfitSpread();
        }).toList()),
      ),
    );
  }

  _buildAppBarView() {
    return AppBar(
      backgroundColor: COLOR.white,
      leading: Icon(
        Icons.arrow_back_ios,
        size: 22.w,
        color: COLOR.color_666666,
      ).onTap(() => Get.back()),
      titleSpacing: 0,
      title: TabBar(
        tabs: titles.map((e) => Tab(text: e)).toList(),
        isScrollable: true,
        tabAlignment: TabAlignment.start,
        padding: EdgeInsets.zero,
        indicator: EasyFixedIndicator(
            borderRadius: Styles.borderRadius.m,
            color: COLOR.hexColor("#B93FFF"),
            width: 10.w,
            height: 3.w),
        labelStyle: TextStyle(color: COLOR.color_333333, fontSize: 16.w),
        unselectedLabelStyle:
            TextStyle(color: COLOR.color_333333, fontSize: 16.w),
        indicatorPadding: EdgeInsets.only(bottom: 5.w),
        dividerHeight: 0,
        labelPadding: EdgeInsets.only(left: 15.w),
      ),
      bottom: PreferredSize(
          preferredSize: const Size.fromHeight(1),
          child: Container(
            height: 1.w,
            width: double.infinity,
            color: COLOR.color_F0F0F0,
          )),
    );
  }
}
